<?php
class Mwc_SystemPoint_ExpireController extends Mage_Adminhtml_Controller_Action{
    public function indexAction(){
        $this->loadLayout()
            ->_addContent($this->getLayout()->createBlock('systempoint/expire_list'))
            ->renderLayout();
    }

    public function deleteAction(){
        $expireId = $this->getRequest()->getParam('id', false);

        try {
            Mage::getModel('systempoint/expire')->setId($expireId)->delete();
            Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('systempoint')->__('Expire row successfully deleted'));
            $this->getResponse()->setRedirect($this->getUrl('*/*/'));

            return;
        }
        catch (Exception $e){
            Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
        }

        $this->_redirectReferer();
    }

    public function newAction(){
        $this->loadLayout()
            ->_addContent($this->getLayout()->createBlock('systempoint/expire_new'))
            ->renderLayout();
    }

    public function postAction(){
        if ($data = $this->getRequest()->getPost()){
            $tip = Mage::getModel('systempoint/expire')->setData($data);
            try{
                $tip->save();
                Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('systempoint')->__('Expire row was successfully saved'));
                $this->getResponse()->setRedirect($this->getUrl('*/*/'));
                return;
            }
            catch (Exception $e){
                Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
            }
        }
        $this->getResponse()->setRedirect($this->getUrl('*/*/'));

        return;
    }

    public function editAction(){
        $this->loadLayout();
        $this->_addContent($this->getLayout()->createBlock('systempoint/expire_edit'));
        $this->renderLayout();
    }

    public function saveAction(){
        $id = $this->getRequest()->getParam('id', false);
        if ($data = $this->getRequest()->getPost()) {
            $expire = Mage::getModel('systempoint/expire')->load($id)->addData($data);
            try {
                $expire->setId($id)->save();

                Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('systempoint')->__('Expire row successfully updated'));
                $this->getResponse()->setRedirect($this->getUrl('*/*/'));
                return;
            }
            catch (Exception $e){
                Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
            }
        }
        $this->_redirectReferer();
    }
}